﻿using Volo.Abp.DependencyInjection;

namespace DDDDemoABP1.DAL;

public class AccountDAL: ITransientDependency
{
    private static List<AccountDALModel> _Accounts = new()
    {
        new(){ UserId = Guid.Parse("e3adb92e-989e-426f-8c8e-b33aa230884a"), AccountNo = "00001", Balance = 1000m },
        new(){ UserId = Guid.Parse("cf7609be-e2dc-430d-b4c0-6f660ec3e9d4"), AccountNo = "00002", Balance = 10m },
        new(){ UserId = Guid.Parse("d1ce9736-1662-4d99-84fb-eb43964f6922"), AccountNo = "00003", Balance = 200m },
        new(){ UserId = Guid.Parse("67b8d022-f8df-4741-af1c-e9b111cc6856"), AccountNo = "00004", Balance = 5m },
    };
    public async Task<AccountDALModel> GetAccountByIdAsync(Guid userId)
    {
        await Task.CompletedTask;
        return _Accounts.FirstOrDefault(r => r.UserId == userId);
    }

    public async Task<AccountDALModel> GetAccountByNoAsync(string no)
    {
        await Task.CompletedTask;
        return _Accounts.FirstOrDefault(r => r.AccountNo == no);
    }

    public async Task UpdateAsync(AccountDALModel account)
    {
        await Task.CompletedTask;
        var ac = _Accounts.FirstOrDefault(r => r.UserId == account.UserId);
        if (ac != null)
        {
            _Accounts.Remove(ac);
        }
        _Accounts.Add(account);
    }

    public async Task AddAsync(AccountDALModel account)
    {
        await Task.CompletedTask;
        _Accounts.Add(account);
    }

    public async Task DeleteAsync(Guid userId)
    {
        await Task.CompletedTask;
        var ac = _Accounts.FirstOrDefault(r => r.UserId == userId);
        if (ac != null)
        {
            _Accounts.Remove(ac);
        }
    }
}
